import GameObject from "../GameObject";
import Utils from "../utils";

export default class SinglePlayObject extends GameObject {
    constructor(x, y, name, parent, pivotX, pivotY, scale) {
        super();
        if (typeof scale === "undefined") {
            scale = 1;
        }

        var anim = Utils.createAnimation(name);
        anim.on(Laya.Event.COMPLETE, this, this.onPlayComp)
        anim.play(0,false);
        anim.scaleX = anim.scaleY = scale;
        // anim.pivotX = pivotX / scale;
        // anim.pivotY = pivotY / scale;
        anim.x = x;
        anim.y = y;
        this.sprite = anim;
        Utils.addChild(this.sprite, parent);
    }

    onPlayComp() {
        this.sprite.stop();
        Utils.removeClip(this.sprite);
        this.destroy();
    }
} 